/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.NVBH;

import DAO.CTHoaDonDao;
import DAO.HoaDonDao;
import DAO.KhachHangDao;
import DAO.NhanVienDao;
import DAO.SanPhamDao;
import POJO.CTHoaDon;
import POJO.HoaDon;
import POJO.KhachHang;
import POJO.NhanVien;
import POJO.SanPham;
import java.sql.Date;
import java.util.ArrayList;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Hồng
 */
public class frCapNhatTrangThaiHoaDon extends javax.swing.JInternalFrame {

	private DefaultListModel listModel;
	private int manv;
	private int makh;
	private HoaDon HD;

	/**
	 * Creates new form frCapNhatTrangThaiHoaDonBanHang
	 */
	public frCapNhatTrangThaiHoaDon() {
		initComponents();
		this.listModel = new DefaultListModel();
		ButtonGroup group = new ButtonGroup();
		group.add(ra1);
		group.add(ra2);
		group.add(ra3);
		HD = new HoaDon();
	}

	private boolean kiemTraNhapSo() {
		try {
			int tmp = Integer.parseInt(jtxtMaHD.getText().trim());
			return true;
		} catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(this, "Chỉ nhập số:", "Thông báo lỗi", JOptionPane.ERROR_MESSAGE);
			jtxtMaHD.requestFocus();
			jtxtMaHD.selectAll();
			return true;
		}

	}

	public boolean KiemTraDuLieu() {
		String str = "";


		if (jtxtMaHD.getText().equals("") || jtxtMaHD.getText().equals(0)) {
			str += "- Nhập mã hoá đơn ! \r\n";
		} else if ((Integer.parseInt(jtxtMaHD.getText())) > HoaDonDao.layMaHDMax()) {
			str += "Hoá đơn chưa tồn tại!!!";
			jtxtMaHD.setText(null);
		}
		if (str.equals("")) {
			return true;
		} else {
			JOptionPane.showMessageDialog(this, str, "Thông báo lỗi", JOptionPane.ERROR_MESSAGE);
			return false;

		}
	}

	public void LoadCTHoaDon(int maHD) {
		ArrayList<CTHoaDon> dsCTHD = CTHoaDonDao.layDSByMaHD(maHD);
		String[] columns = new String[]{"STT", "Sản phẩm", "Số lượng", "Giá bán", "Tổng tiền"};

		DefaultTableModel model = new DefaultTableModel(null, columns);
		int i = 1;
		for (CTHoaDon cthd : dsCTHD) {

			SanPham sp = SanPhamDao.LaySanPhamByMa(cthd.getMaSP());
			Object[] items = new Object[]{
				i,
				sp.getTenSP(),
				cthd.getSoLuong(),
				cthd.getGiaBan(),
				(cthd.getGiaBan()) * (cthd.getSoLuong())};

			i++;
			model.addRow(items);
		}

		tbChiTiet.setModel(model);
		int[] va = {10, 30, 20, 20, 20};
		int[] pt = new int[5];
		for (int l = 0;
			 l < 5; l++) {
			pt[l] = tbChiTiet.getWidth() * va[l] / 100;
			tbChiTiet.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);
		}
	}

	public void khoaTatCaRa() {
		// khoa tat ca cac ra
		ra1.setEnabled(false);
		ra2.setEnabled(false);
		ra3.setEnabled(false);

		ra1.setSelected(false);
		ra2.setSelected(false);
		ra3.setSelected(false);


	}

	public void LoadHoaDon() {
		khoaTatCaRa();

		if (HD.getTrangThai() == 2) {
			ra2.setSelected(true);
		}
		if (HD.getTrangThai() == 3) {
			ra3.setSelected(true);

		}
		if (HD.getTrangThai() == 1) {
			ra1.setSelected(true);
			ra2.setEnabled(true);
		}
		KhachHangDao khd = new KhachHangDao();
		NhanVienDao nvd = new NhanVienDao();
		NhanVien nv = new NhanVien();
		nv = nvd.layByMa(HD.getMaNVPhuTrach());
		KhachHang kh = new KhachHang();
		kh = khd.layByMa(HD.getMaKH());
		jtxtTenNV.setText(nv.getTenNV());
		jtxtTenKH.setText(kh.getTenKH());
		jtxtNgayLapHD.setText(String.valueOf((HD.getNgayLap())));
		jtxtTriGia.setText(String.valueOf(HD.getTriGia()));
		jtxtTienGiam.setText(String.valueOf(HD.getSoTienGiam()));
		manv = HD.getMaNVPhuTrach();
		makh = HD.getMaKH();
		double tien = 0;
		double trigia = (HD.getTriGia());
		double tiengiam = HD.getSoTienGiam();
		tien = trigia - tiengiam;
		jtxtTien.setText(String.valueOf(tien));



	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
       private void initComponents() {

              jPanel1 = new javax.swing.JPanel();
              jLabel1 = new javax.swing.JLabel();
              jPanel2 = new javax.swing.JPanel();
              jPanel4 = new javax.swing.JPanel();
              jLabel2 = new javax.swing.JLabel();
              jtxtMaHD = new javax.swing.JTextField();
              jbtTim = new javax.swing.JButton();
              jLabel5 = new javax.swing.JLabel();
              jtxtTenNV = new javax.swing.JTextField();
              jLabel3 = new javax.swing.JLabel();
              jtxtTenKH = new javax.swing.JTextField();
              jLabel4 = new javax.swing.JLabel();
              jtxtNgayLapHD = new javax.swing.JTextField();
              jLabel6 = new javax.swing.JLabel();
              jtxtTriGia = new javax.swing.JTextField();
              jLabel7 = new javax.swing.JLabel();
              jtxtTienGiam = new javax.swing.JTextField();
              jLabel8 = new javax.swing.JLabel();
              jtxtTien = new javax.swing.JTextField();
              jLabel9 = new javax.swing.JLabel();
              jLabel10 = new javax.swing.JLabel();
              jLabel11 = new javax.swing.JLabel();
              jbtHuy = new javax.swing.JButton();
              jPanel5 = new javax.swing.JPanel();
              jLabel13 = new javax.swing.JLabel();
              jbtCapNhatTrangThai = new javax.swing.JButton();
              ra2 = new javax.swing.JRadioButton();
              ra1 = new javax.swing.JRadioButton();
              ra3 = new javax.swing.JRadioButton();
              jPanel3 = new javax.swing.JPanel();
              jScrollPane1 = new javax.swing.JScrollPane();
              tbChiTiet = new javax.swing.JTable();

              setClosable(true);
              setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
              setIconifiable(true);
              setMaximizable(true);
              setResizable(true);

              jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
              jLabel1.setText("CẬP NHẬT TRẠNG THÁI HÓA ĐƠN");

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel1Layout.setVerticalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addComponent(jLabel1)
                            .addGap(0, 0, 0))
              );

              jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Tìm hóa đơn"));

              jLabel2.setText("Mã hóa đơn:");

              jtxtMaHD.addKeyListener(new java.awt.event.KeyAdapter() {
                     public void keyReleased(java.awt.event.KeyEvent evt) {
                            jtxtMaHDKeyReleased(evt);
                     }
              });

              jbtTim.setText("Tìm");
              jbtTim.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtTimActionPerformed(evt);
                     }
              });

              jLabel5.setText("Nhân viên  bán:");

              jtxtTenNV.setEnabled(false);

              jLabel3.setText("Tên khách hàng:");

              jtxtTenKH.setEnabled(false);

              jLabel4.setText("Ngày lập:");

              jtxtNgayLapHD.setEnabled(false);
              jtxtNgayLapHD.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtxtNgayLapHDActionPerformed(evt);
                     }
              });

              jLabel6.setText("Trị giá:");

              jtxtTriGia.setEnabled(false);
              jtxtTriGia.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtxtTriGiaActionPerformed(evt);
                     }
              });

              jLabel7.setText("Số tiền giảm:");

              jtxtTienGiam.setEnabled(false);
              jtxtTienGiam.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtxtTienGiamActionPerformed(evt);
                     }
              });

              jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jLabel8.setText("Tiền phải thu:");

              jtxtTien.setEditable(false);
              jtxtTien.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtxtTienActionPerformed(evt);
                     }
              });

              jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jLabel9.setText("VNĐ");

              jLabel10.setText("VNĐ");

              jLabel11.setText("VNĐ");

              jbtHuy.setText("Hủy");
              jbtHuy.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtHuyActionPerformed(evt);
                     }
              });

              javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
              jPanel4.setLayout(jPanel4Layout);
              jPanel4Layout.setHorizontalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel4Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jtxtMaHD, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jtxtTenNV, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jtxtTenKH, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jtxtNgayLapHD, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jtxtTriGia, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jtxtTienGiam, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jtxtTien, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jLabel9)
                                   .addComponent(jLabel10)
                                   .addComponent(jLabel11)
                                   .addComponent(jbtTim, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jbtHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel4Layout.setVerticalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel4Layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtxtMaHD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel2)
                                   .addComponent(jbtTim))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtxtTenNV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel5)
                                   .addComponent(jbtHuy))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtxtTenKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel3))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtxtNgayLapHD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel4))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtxtTriGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel6)
                                   .addComponent(jLabel11))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtxtTienGiam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel7)
                                   .addComponent(jLabel10))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtxtTien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel8)
                                   .addComponent(jLabel9))
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Cập nhật"));

              jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jLabel13.setText("Trạng thái:");

              jbtCapNhatTrangThai.setText("Cập nhật");
              jbtCapNhatTrangThai.setEnabled(false);
              jbtCapNhatTrangThai.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtCapNhatTrangThaiActionPerformed(evt);
                     }
              });

              ra2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              ra2.setText("Đã thanh toán");
              ra2.setEnabled(false);
              ra2.addChangeListener(new javax.swing.event.ChangeListener() {
                     public void stateChanged(javax.swing.event.ChangeEvent evt) {
                            ra2StateChanged(evt);
                     }
              });
              ra2.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            ra2ActionPerformed(evt);
                     }
              });

              ra1.setText("Chưa thanh toán");
              ra1.setEnabled(false);

              ra3.setText("Hoàn tất");
              ra3.setEnabled(false);

              javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
              jPanel5.setLayout(jPanel5Layout);
              jPanel5Layout.setHorizontalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel5Layout.createSequentialGroup()
                            .addComponent(jbtCapNhatTrangThai, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, Short.MAX_VALUE))
                     .addGroup(jPanel5Layout.createSequentialGroup()
                            .addGap(21, 21, 21)
                            .addComponent(jLabel13)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(ra3)
                                   .addComponent(ra1)
                                   .addComponent(ra2))
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel5Layout.setVerticalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel5Layout.createSequentialGroup()
                            .addGap(37, 37, 37)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel13)
                                   .addComponent(ra1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(ra2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(ra3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbtCapNhatTrangThai))
              );

              javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
              jPanel2.setLayout(jPanel2Layout);
              jPanel2Layout.setHorizontalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel2Layout.setVerticalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                   .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(0, 0, 0))
              );

              jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Chi tiết hóa đơn"));

              tbChiTiet.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Sản phẩm", "Số lượng", "Giá bán", "Tổng tiền"
                     }
              ));
              jScrollPane1.setViewportView(tbChiTiet);

              javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
              jPanel3.setLayout(jPanel3Layout);
              jPanel3Layout.setHorizontalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGap(0, 0, Short.MAX_VALUE)
                     .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 683, Short.MAX_VALUE))
              );
              jPanel3Layout.setVerticalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGap(0, 205, Short.MAX_VALUE)
                     .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE))
              );

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
              );
              layout.setVerticalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );

              pack();
       }// </editor-fold>//GEN-END:initComponents

       private void jtxtNgayLapHDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtNgayLapHDActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtxtNgayLapHDActionPerformed

    private void jbtTimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtTimActionPerformed
	    khoaTatCaRa();
	    if (KiemTraDuLieu()) {
		    int maHD = Integer.parseInt(this.jtxtMaHD.getText());

		    HD = HoaDonDao.layByMa(maHD);

		    if (HD == null) {
			    JOptionPane.showMessageDialog(this, "Không tìm thấy", "Cảnh báo!!!", JOptionPane.ERROR_MESSAGE);
		    } else {
			    LoadHoaDon();
			    LoadCTHoaDon(HD.getMaHD());
			    jbtTim.setEnabled(false);
			    jtxtMaHD.setEditable(false);
		    }
	    } else {
		    jtxtMaHD.requestFocus();
	    }
    }//GEN-LAST:event_jbtTimActionPerformed

    private void jbtCapNhatTrangThaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCapNhatTrangThaiActionPerformed

	    boolean kq = false;
	    try {
		    kq = HoaDonDao.capNhatTrangThai(HD);

	    } catch (Exception e) {
		    JOptionPane.showMessageDialog(this, "Cập nhật trạng thái thất bại", "Cảnh báo!!!", JOptionPane.WARNING_MESSAGE);
	    }
	    if (kq == true) {
		    JOptionPane.showMessageDialog(this, "Hoá đơn đã được thanh toán", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
		    //LoadCTHoaDon(Integer.parseInt(this.jtxtMaHD.getText()));
		    jbtTim.setEnabled(true);
		    jbtCapNhatTrangThai.setEnabled(false);
		    jtxtMaHD.setEditable(true);
	    }

    }//GEN-LAST:event_jbtCapNhatTrangThaiActionPerformed

       private void jtxtTriGiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtTriGiaActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtxtTriGiaActionPerformed

       private void jtxtTienGiamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtTienGiamActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtxtTienGiamActionPerformed

       private void jtxtTienActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtTienActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtxtTienActionPerformed

       private void ra2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_ra2StateChanged
		// TODO add your handling code here:
		HD.setTrangThai(2);
       }//GEN-LAST:event_ra2StateChanged

       private void jbtHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtHuyActionPerformed
		// TODO add your handling code here:
		jbtTim.setEnabled(true);
		jbtCapNhatTrangThai.setEnabled(false);
		jtxtMaHD.setEditable(true);
		jtxtMaHD.requestFocus();
		jtxtMaHD.selectAll();

       }//GEN-LAST:event_jbtHuyActionPerformed

       private void ra2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ra2ActionPerformed
		// TODO add your handling code here:
		if (jtxtMaHD.getText().trim().equals("")) {
			return;
		} else {
			jbtCapNhatTrangThai.setEnabled(true);
		}
		ra2.setEnabled(false);
       }//GEN-LAST:event_ra2ActionPerformed

       private void jtxtMaHDKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtxtMaHDKeyReleased
		// TODO add your handling code here:
		kiemTraNhapSo();
       }//GEN-LAST:event_jtxtMaHDKeyReleased
       // Variables declaration - do not modify//GEN-BEGIN:variables
       private javax.swing.JLabel jLabel1;
       private javax.swing.JLabel jLabel10;
       private javax.swing.JLabel jLabel11;
       private javax.swing.JLabel jLabel13;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel3;
       private javax.swing.JLabel jLabel4;
       private javax.swing.JLabel jLabel5;
       private javax.swing.JLabel jLabel6;
       private javax.swing.JLabel jLabel7;
       private javax.swing.JLabel jLabel8;
       private javax.swing.JLabel jLabel9;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel2;
       private javax.swing.JPanel jPanel3;
       private javax.swing.JPanel jPanel4;
       private javax.swing.JPanel jPanel5;
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JButton jbtCapNhatTrangThai;
       private javax.swing.JButton jbtHuy;
       private javax.swing.JButton jbtTim;
       private javax.swing.JTextField jtxtMaHD;
       private javax.swing.JTextField jtxtNgayLapHD;
       private javax.swing.JTextField jtxtTenKH;
       private javax.swing.JTextField jtxtTenNV;
       private javax.swing.JTextField jtxtTien;
       private javax.swing.JTextField jtxtTienGiam;
       private javax.swing.JTextField jtxtTriGia;
       private javax.swing.JRadioButton ra1;
       private javax.swing.JRadioButton ra2;
       private javax.swing.JRadioButton ra3;
       private javax.swing.JTable tbChiTiet;
       // End of variables declaration//GEN-END:variables
}
